#ifndef __CarD1_Detect_C
#define __CarD1_Detect_C

#include "CarD1_Detect.h"

void carD1_Detect_init(){
    GPIO_Config_T     configStruct;
	  #if CarD1_Detect_Tyte == CarD1_Detect_EINT
	  EINT_Config_T     EINT_configStruct;
    #endif
	    
    RCM_EnableAPB2PeriphClock(CarD1_RTC);
    configStruct.mode = GPIO_MODE_IN_FLOATING; //浮空输入	  
    configStruct.pin  = CarD1_PinId;
	
    GPIO_Config(CarD1_PinPort, &configStruct);  

    #if CarD1_Detect_Tyte == CarD1_Detect_EINT
			// 外部中断初始化	     
			RCM_EnableAPB2PeriphClock(CarD1_RCM_EINT); 
			GPIO_ConfigEINTLine(CarD1_EintPort, CarD1_EintPin); 
			// 配置外部中断  
	    #ifdef AT32F403AVGT7
	    exint_default_para_init(&EINT_configStruct);
	    #endif
			EINT_configStruct.line    = CarD1_EintLine;	    
			EINT_configStruct.mode    = EINT_MODE_INTERRUPT;
			EINT_configStruct.trigger = EINT_TRIGGER_FALLING; //下降沿
			EINT_configStruct.lineCmd = ENABLE;
			EINT_Config(&EINT_configStruct);
	  #endif
		
}

#if CarD1_Detect_Tyte == CarD1_Detect_OCC_Trg
uint8_t carD1_get_level(){
	  return GPIO_ReadInputBit(CarD1_PinPort, CarD1_PinId);
}
#endif

#if CarD1_Detect_Tyte == CarD1_Detect_EINT
void carD1_detect_start(){	
    //这里的初始化，只是改变上面修改过的参数，其余的不变  
	  // nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
	  NVIC_EnableIRQRequest(CarD1_Eint_IRQn, 0, 0);	  
}
void carD1_detect_stop(){	  
	  NVIC_DisableIRQRequest(CarD1_Eint_IRQn);
}
#endif

#endif


